import aiosqlite


class DatabasePool:
    _pool = None  # 类属性保存连接池实例

    @classmethod
    async def create_pool(cls, db_path):
        """创建数据库连接池"""
        cls._pool = await aiosqlite.connect(db_path)
        print("Database connection pool initialized")

    @classmethod
    async def get_connection(cls):
        """从连接池获取连接"""
        if cls._pool is None:
            raise RuntimeError("Database pool is not initialized")
        return cls._pool

    @classmethod
    async def close_pool(cls):
        """关闭连接池"""
        if cls._pool:
            await cls._pool.close()
            print("Database connection pool closed")